package com.banzhi.shop.activity;

import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.adapter.MyCollegeAdapter;
import com.banzhi.shop.adapter.MyShopAdapter;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.fragment.College_DaifaFragment;
import com.banzhi.shop.fragment.College_YifaFragment;

import com.banzhi.shop.fragment.Shouyi_DaifaFragment;
import com.banzhi.shop.fragment.Shouyi_YifaFragment;
import com.banzhi.shop.utils.TabLayoutUtil;
import com.banzhi.shop.utils.Translucent;
import com.banzhi.shop.view.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;
// 收益明细
public class CollegeActivity extends BaseActivity implements View.OnClickListener {

    private TabLayout tabs;
    private ViewPager viewPager;
    private List<String> mTitle = new ArrayList<String>();
    private List<Fragment> mFragment = new ArrayList<Fragment>();

    private List<String> mTitle2 = new ArrayList<>();
    private List<Fragment> mFragment2 = new ArrayList<>();

    private TabLayout TabsShop;
    private TabLayout tabsCollege;
   // private ViewPager VpCollege;


    private ImageView IvBackCollege;
    private TextView TvShop;
    private TextView TvCollege;

    private NoScrollViewPager vpShop;
    private NoScrollViewPager vpCollege;

    private LinearLayout llShopProfit;
    private LinearLayout llCollegeProfit;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_college);
        Translucent.setTranslucent(this);
        initView();
        setlisteners();

        MyCollegeAdapter myShopAdaper = new MyCollegeAdapter(getSupportFragmentManager(), mTitle, mFragment);
        vpShop.setAdapter(myShopAdaper);
        //为TabLayout设置ViewPager
        TabsShop.setupWithViewPager(vpShop);
        //使用ViewPager的适配器
        TabsShop.setTabsFromPagerAdapter(myShopAdaper);
        //定义tablayout下划线的长度
        TabsShop.post(new Runnable() {
            @Override
            public void run() {
                TabLayoutUtil.setIndicator(TabsShop, 30, 30);
            }
        });


        MyShopAdapter myCollegeAdapter = new MyShopAdapter(getSupportFragmentManager(), mTitle2, mFragment2);
        vpCollege.setAdapter(myCollegeAdapter);
        //为TabLayout设置ViewPager
        tabsCollege.setupWithViewPager(vpCollege);
        //使用ViewPager的适配器
        tabsCollege.setTabsFromPagerAdapter(myCollegeAdapter);

        tabsCollege.post(new Runnable() {
            @Override
            public void run() {
                TabLayoutUtil.setIndicator(tabsCollege, 30, 30);
            }
        });

    }

    private void initView() {
        IvBackCollege = (ImageView) findViewById(R.id.iv_back_college);
        TvShop = (TextView) findViewById(R.id.tv_shop);
        TvCollege = (TextView) findViewById(R.id.tv_college);
        vpShop = (NoScrollViewPager) findViewById(R.id.vp_shop);
        vpCollege = (NoScrollViewPager) findViewById(R.id.vp_college);

        TabsShop = (TabLayout) findViewById(R.id.tabs_shop);
        tabsCollege = (TabLayout) findViewById(R.id.tabs_college);
        llShopProfit = (LinearLayout) findViewById(R.id.ll_shop_profit);
        llCollegeProfit = (LinearLayout) findViewById(R.id.ll_college_profit);
        // VpCollege = (ViewPager) findViewById(R.id.vp_college);
        mTitle.add("待发放");
        mTitle.add("已发放");

       /* mFragment.add(new CollegeTab2Fragment());
        mFragment.add(new CollegeTab2Fragment());*/
         mFragment.add(new Shouyi_DaifaFragment());

        mFragment.add(new Shouyi_YifaFragment());

        mTitle2.add("待发放");
        mTitle2.add("已发放");

        mFragment2.add(new College_DaifaFragment());
        mFragment2.add(new College_YifaFragment());



    }

    private void setlisteners() {
        IvBackCollege.setOnClickListener(this);
        TvShop.setOnClickListener(this);
        TvCollege.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back_college:
                finish();
                break;
            case R.id.tv_shop:
                TvCollege.setBackgroundResource(R.mipmap.bg2);
                TvCollege.setTextColor(Color.WHITE);
                llShopProfit.setVisibility(View.VISIBLE);
                llCollegeProfit.setVisibility(View.GONE);
                TvShop.setBackgroundResource(R.mipmap.bg1);
                TvShop.setTextColor(ContextCompat.getColor(this, R.color.themeColor));
                break;
            case R.id.tv_college:
                TvCollege.setBackgroundResource(R.mipmap.bg5);
                TvCollege.setTextColor(ContextCompat.getColor(this, R.color.themeColor));
                llCollegeProfit.setVisibility(View.VISIBLE);
                llShopProfit.setVisibility(View.GONE);
                TvShop.setBackgroundResource(R.mipmap.bg4);
                TvShop.setTextColor(Color.WHITE);
                break;
        }

    }
}
